As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label shell builtin. Show all posts

I just accidentally discovered there is a Bash builtin help (by typing hel for auto-complete), and it is really helpful.

The following is an example:
$ help help
help: help [-dms] [pattern ...]
    Display information about builtin commands.
    
    Displays brief summaries of builtin commands.  If PATTERN is
    specified, gives detailed help on all commands matching PATTERN,
    otherwise the list of help topics is printed.
    
    Options:
      -d        output short description for each topic
      -m        display usage in pseudo-manpage format
      -s        output only a short usage synopsis for each topic matching
        PATTERN
    
    Arguments:
      PATTERN   Pattern specifiying a help topic
    
    Exit Status:
    Returns success unless PATTERN is not found or an invalid option is given.
You can read the options, arguments, and explanations. I realized I had spent (wasted) too much time on scrolling and searching in Bash manpage for the same stuff.

A year ago, I didn't even know you can write a C code for Bash extension. Yesterday, I stumbled on Using and Writing Bash Dynamically Loadable Built-In Commands and I knew I could do something with this new discovery.

So, I wrote a C code for replacing my Bash version script. The speed is only three times fast, I am so disappointed I expected much faster. Anyway, it's really hardly can gain much from improving PS1, it's not as if your PS1 is required to update 1000 times per second.

You can go check some loadable builtins comes with Bash, they should be installed at /usr/lib[64]/bash/. Use enable <name> to enable and to disable with -d.

If you want to develop your own builtin, you will need to download the Bash source code. I doubt any distro will install header files of Bash for you. A basic ./configure is needed to generate necessary header files and also you will need to run make pathnames.h for that header at least.